<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
        window.onload=function()
        {
            var btn=document.getElementsByTagName("button");
            console.log(btn);
            //注意：此次遍历btn数组的元素时，要使用let而不是var
            for(let i=0;i<btn.length;i++)
            {
                btn[i].onclick=function()
                {
                    console.log("点击的是第"+(i+1)+"个按钮");
                }
            }
        };
        
    </script>
</head>
<body>
    <button>测试1</button>
    <button>测试2</button>
    <button>测试3</button>
    <button>测试4</button>
    <button>测试5</button>
    <button>测试6</button>
    <button>测试7</button>
    <!--
        需求：点击某个按钮，提示“点击的是第N个按钮
    -->
</body>
</html>